package com.example.mysql_mybatis_demo.springsource.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.UUID;

@Configuration
public class FactoryBeanAnnotationTest {
    /**
     * 此时就相当于声明了一个名为 nonBeanTestTir的FactoryBean，它同样返回一个 NonBeanTest的Bean实例.
     * 注解@Bean可以显式指定Bean的名称，如不指定，则默认使用方法名作为Bean的名称
     * @return
     */
    @Bean
    public NonBeanTest nonBeanTestTir(){
        NonBeanTest nonBeanTestTir = new NonBeanTest();
        nonBeanTestTir.setName("NonBean_Tir_" + UUID.randomUUID().toString().substring(0,5));
        return nonBeanTestTir;
    }

    /**
     * 此时就相当于声明了一个名为 nonBeanTestFor 的FactoryBean，同样返回一个 NonBeanTest的Bean实例
     * @return
     */
    @Bean
    public NonBeanTest nonBeanTestFor(){
        NonBeanTest nonBeanTestFor = new NonBeanTest();
        nonBeanTestFor.setName("NonBean_For_" + UUID.randomUUID().toString().substring(0,5));
        return nonBeanTestFor;
    }
}
